<?php

include_once 'AFClass.class.php';

class AFCollection extends AFClass implements IteratorAggregate, ArrayAccess
{
	private $values = array();

	public function __construct($source = NULL)
	{
		if($source && (is_array($source) || ($source instanceOf ArrayObject)))
		{
			$this->values = $source;
		}
	}

	public function offsetGet($offset)
	{
		return isset($this->values[$offset]) ? $this->values[$offset] : NULL;
	}

	public function offsetSet($offset, $value)
	{
		$this->values[$offset] = $value;
	}

	public function offsetUnset($offset)
	{
		if(isset($this->values[$offset]))
		{
			unset($this->values[$offset]);
		}
	}

	public function offsetExists($offset)
	{
		return isset($this->values[$offset]);
	}

	public function getIterator()
	{
		return $this;
	}

	public function each($callback)
	{
		foreach($this->values as $value)
		{
			$callback($value);
		}
	}

	public function count()
	{
		return count($this->values);
	}
}

?>
